#https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/index.html
#https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/get-started/index.html
sudo apt-get install git wget flex bison gperf python python-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util
sudo apt-get install python3 python3-pip python3-setuptools
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
git clone https://gitee.com/EspressifSystems/esp-idf.git
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
./esp-gitee-tools/submodule-update.sh esp-idf
./esp-idf/install.sh
export IDF_PATH=`pwd`/esp-idf
. ./esp-idf/export.sh
if [ ! -e /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko ]; then
	if [ -e cp210x.ko ]; then

		sudo cp cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial
		sudo rmmod cp210x.ko
		sudo rmmod /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko
		sudo insmod /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko
		sudo insmod cp210x.ko
		sudo usermod -a -G dialout $USER
	elif [ -e Linux_3.x.x_VCP_Driver_Source ]; then
		cd Linux_3.x.x_VCP_Driver_Source
		make
		sudo cp cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial
		sudo rmmod cp210x.ko
		sudo rmmod /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko
		sudo insmod /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko
		sudo insmod cp210x.ko
		sudo usermod -a -G dialout $USER
		cd ..
	fi
fi


rm -rf test
mkdir test
cp -rf esp-idf/examples/get-started/hello_world test
cd test/hello_world
idf.py set-target esp32
idf.py menuconfig
idf.py build
sudo chmod 777 /dev/ttyUSB0
idf.py -p /dev/ttyUSB0 flash monitor
#ctrl+] 退出监视器
cd ../../
